package com.fruits.login.dao;

import com.fruits.login.model.PlayerLoginInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

@Mapper
public interface PlayerInfoDAO {

    /**
     * 根据 deviceMac 查询玩家信息
     * @param deviceMac
     * @return
     */
    @Select("select * from  playerLogin where deviceMac = #{deviceMac}")
    List<PlayerLoginInfo> findPlayerInfoByMac(String deviceMac);
    /**
     * 根据 uid 查询玩家信息
     * @param uid
     * @return
     */
    @Select("select * from  playerLogin where uid = #{uid}")
    List<PlayerLoginInfo> findPlayerInfoByUid(String uid);

    /**根据 phone 查询玩家信息*/
    @Select("select * from  playerLogin p where p.phone = #{phone}")
    List<PlayerLoginInfo> findByPhone(PlayerLoginInfo playerLoginInfo);

    /**注册账号:有手机号*/
    @Insert("insert into playerLogin(phone,uid,deviceMac,type,createTime) values (#{phone},#{uid},#{deviceMac},#{type},#{timestamp})")
    void createPlayerHavePhone(PlayerLoginInfo playerLoginInfo);

    /**注册账号:没有手机号*/
    @Insert("insert into playerLogin(uid,deviceMac,createTime,type) values (#{uid},#{deviceMac},#{timestamp},#{type})")
    void createPlayerNotPhone(PlayerLoginInfo playerLoginInfo);


    /**
     * 手机登录时查看是否有对应手机玩家
     * @param phone
     * @return
     */
    @Select("select * from playerLogin where phone = #{phone}")
    List<PlayerLoginInfo> isHavePlayerByPhone(String phone);

    /**
     * 查出所有的uid
     */
    @Select("select uid from playerLogin")
    List<String> findUidAll();

    /**
     * 大厅绑定手机,修改手机号:uid
     * @param hall
     */
    @Update("update playerlogin set phone = #{phone},type = #{type} where uid = #{uid}")
    void updatePhone(PlayerLoginInfo hall);

    /**
     * 登录绑定手机号:mac
     */
    @Update("update playerlogin set phone = #{phone},type = #{type} where deviceMac = #{deviceMac}")
    void updatePlayerInfoBy(PlayerLoginInfo playerLoginInfo);

}
